<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use think\Db;
class Admin extends Base
{
    public function edit()
    {
        if(request()->isAjax()){
            $params = input('post.');
            if($params['password'] && !empty($params['password'])){
                $params['password'] = strtolower(md5($params['password']));
            }else{
                unset($params['password']);
            }
            $result = Db::name('admin')->where(array('id'=>1))->update($params);
            if($result===false){
                exit(json_encode(array('status'=>'n','info'=>'数据修改失败!')));
            }else{
                session(null);
                exit(json_encode(array('status'=>'y','info'=>'数据修改成功!')));
            }
        }else{
            $admin = Db::name('admin')->field('username')->select();
            $this->assign('admin',$admin);
        }
        return view();
    }
}